<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="用户名(唯一但可能会改),如:@TwitterDev" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入用户名(唯一但可能会改),如:@TwitterDev"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户名(不唯一),如:Twitter Dev" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入用户名(不唯一),如:Twitter Dev"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="推特用户创建时间(UTC)" prop="createdAt">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.createdAt"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择推特用户创建时间(UTC)">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="个人资料描述" prop="description">-->
<!--        <el-input-->
<!--          v-model="queryParams.description"-->
<!--          placeholder="请输入个人资料描述"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="用户置顶推文ID" prop="pinnedTweetId">-->
<!--        <el-input-->
<!--          v-model="queryParams.pinnedTweetId"-->
<!--          placeholder="请输入用户置顶推文ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="用户头像" prop="profileImageUrl">-->
<!--        <el-input-->
<!--          v-model="queryParams.profileImageUrl"-->
<!--          placeholder="请输入用户头像"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="推文是否设置为私有,0否1是" prop="Protected">-->
<!--        <el-input-->
<!--          v-model="queryParams.Protected"-->
<!--          placeholder="请输入推文是否设置为私有,0否1是"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="粉丝数" prop="followersCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.followersCount"-->
<!--          placeholder="请输入粉丝数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="关注者" prop="followingCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.followingCount"-->
<!--          placeholder="请输入关注者"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="推文数" prop="tweetCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.tweetCount"-->
<!--          placeholder="请输入推文数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="列表数" prop="listedCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.listedCount"-->
<!--          placeholder="请输入列表数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="统计的推文数量" prop="queryTweetsNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.queryTweetsNumber"-->
<!--          placeholder="请输入统计的推文数量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="推文总点赞数" prop="tweetsLikeCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.tweetsLikeCount"-->
<!--          placeholder="请输入推文总点赞数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="单推文最高点赞数" prop="tweetsMostLikeCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.tweetsMostLikeCount"-->
<!--          placeholder="请输入单推文最高点赞数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="推文总转发数" prop="tweetsRetweetCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.tweetsRetweetCount"-->
<!--          placeholder="请输入推文总转发数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="单推文最高转发数" prop="tweetsMostRetweetCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.tweetsMostRetweetCount"-->
<!--          placeholder="请输入单推文最高转发数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="推文被引用数" prop="tweetsQuoteCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.tweetsQuoteCount"-->
<!--          placeholder="请输入推文被引用数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="推文总评论数" prop="tweetsReplyCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.tweetsReplyCount"-->
<!--          placeholder="请输入推文总评论数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="单推文最高评论数" prop="tweetsMostReplyCount">-->
<!--        <el-input-->
<!--          v-model="queryParams.tweetsMostReplyCount"-->
<!--          placeholder="请输入单推文最高评论数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="推文中包含关键字的条数" prop="tweetsKeywordNumber">-->
<!--        <el-input-->
<!--          v-model="queryParams.tweetsKeywordNumber"-->
<!--          placeholder="请输入推文中包含关键字的条数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最新的推文发布时间(UTC)" prop="latestTweetTime">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.latestTweetTime"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择最新的推文发布时间(UTC)">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否优先抓取" prop="priorityCrawl">-->
<!--        <el-input-->
<!--          v-model="queryParams.priorityCrawl"-->
<!--          placeholder="请输入是否优先抓取"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否已经从他抓取其他人" prop="searchedOthers">-->
<!--        <el-input-->
<!--          v-model="queryParams.searchedOthers"-->
<!--          placeholder="请输入是否已经从他抓取其他人"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:twuser:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:twuser:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:twuser:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:twuser:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="twuserList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="本系统用户唯一标识ID" align="center" prop="id" />
      <el-table-column label="用户名(唯一但可能会改),如:@TwitterDev" align="center" prop="username" />
      <el-table-column label="用户名(不唯一),如:Twitter Dev" align="center" prop="name" />
      <el-table-column label="推特用户创建时间(UTC)" align="center" prop="createdAt" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createdAt, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="个人资料描述" align="center" prop="description" />
      <el-table-column label="用户置顶推文ID" align="center" prop="pinnedTweetId" />
      <el-table-column label="用户头像" align="center" prop="profileImageUrl" />
      <el-table-column label="推文是否设置为私有,0否1是" align="center" prop="Protected" />
      <el-table-column label="粉丝数" align="center" prop="followersCount" />
      <el-table-column label="关注者" align="center" prop="followingCount" />
      <el-table-column label="推文数" align="center" prop="tweetCount" />
      <el-table-column label="列表数" align="center" prop="listedCount" />
      <el-table-column label="统计的推文数量" align="center" prop="queryTweetsNumber" />
      <el-table-column label="推文总点赞数" align="center" prop="tweetsLikeCount" />
      <el-table-column label="单推文最高点赞数" align="center" prop="tweetsMostLikeCount" />
      <el-table-column label="推文总转发数" align="center" prop="tweetsRetweetCount" />
      <el-table-column label="单推文最高转发数" align="center" prop="tweetsMostRetweetCount" />
      <el-table-column label="推文被引用数" align="center" prop="tweetsQuoteCount" />
      <el-table-column label="推文总评论数" align="center" prop="tweetsReplyCount" />
      <el-table-column label="单推文最高评论数" align="center" prop="tweetsMostReplyCount" />
      <el-table-column label="推文中包含关键字的条数" align="center" prop="tweetsKeywordNumber" />
      <el-table-column label="最新的推文发布时间(UTC)" align="center" prop="latestTweetTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.latestTweetTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否优先抓取" align="center" prop="priorityCrawl" />
      <el-table-column label="是否已经从他抓取其他人" align="center" prop="searchedOthers" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:twuser:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:twuser:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改推特用户基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="推特用户唯一表示ID" prop="twUserId">
          <el-input v-model="form.twUserId" placeholder="请输入推特用户唯一表示ID" />
        </el-form-item>
        <el-form-item label="用户名(唯一但可能会改),如:@TwitterDev" prop="username">
          <el-input v-model="form.username" placeholder="请输入用户名(唯一但可能会改),如:@TwitterDev" />
        </el-form-item>
        <el-form-item label="用户名(不唯一),如:Twitter Dev" prop="name">
          <el-input v-model="form.name" placeholder="请输入用户名(不唯一),如:Twitter Dev" />
        </el-form-item>
        <el-form-item label="推特用户创建时间(UTC)" prop="createdAt">
          <el-date-picker clearable
            v-model="form.createdAt"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择推特用户创建时间(UTC)">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="个人资料描述" prop="description">
          <el-input v-model="form.description" placeholder="请输入个人资料描述" />
        </el-form-item>
        <el-form-item label="用户置顶推文ID" prop="pinnedTweetId">
          <el-input v-model="form.pinnedTweetId" placeholder="请输入用户置顶推文ID" />
        </el-form-item>
        <el-form-item label="用户头像" prop="profileImageUrl">
          <el-input v-model="form.profileImageUrl" placeholder="请输入用户头像" />
        </el-form-item>
        <el-form-item label="推文是否设置为私有,0否1是" prop="Protected">
          <el-input v-model="form.Protected" placeholder="请输入推文是否设置为私有,0否1是" />
        </el-form-item>
        <el-form-item label="粉丝数" prop="followersCount">
          <el-input v-model="form.followersCount" placeholder="请输入粉丝数" />
        </el-form-item>
        <el-form-item label="关注者" prop="followingCount">
          <el-input v-model="form.followingCount" placeholder="请输入关注者" />
        </el-form-item>
        <el-form-item label="推文数" prop="tweetCount">
          <el-input v-model="form.tweetCount" placeholder="请输入推文数" />
        </el-form-item>
        <el-form-item label="列表数" prop="listedCount">
          <el-input v-model="form.listedCount" placeholder="请输入列表数" />
        </el-form-item>
        <el-form-item label="统计的推文数量" prop="queryTweetsNumber">
          <el-input v-model="form.queryTweetsNumber" placeholder="请输入统计的推文数量" />
        </el-form-item>
        <el-form-item label="推文总点赞数" prop="tweetsLikeCount">
          <el-input v-model="form.tweetsLikeCount" placeholder="请输入推文总点赞数" />
        </el-form-item>
        <el-form-item label="单推文最高点赞数" prop="tweetsMostLikeCount">
          <el-input v-model="form.tweetsMostLikeCount" placeholder="请输入单推文最高点赞数" />
        </el-form-item>
        <el-form-item label="推文总转发数" prop="tweetsRetweetCount">
          <el-input v-model="form.tweetsRetweetCount" placeholder="请输入推文总转发数" />
        </el-form-item>
        <el-form-item label="单推文最高转发数" prop="tweetsMostRetweetCount">
          <el-input v-model="form.tweetsMostRetweetCount" placeholder="请输入单推文最高转发数" />
        </el-form-item>
        <el-form-item label="推文被引用数" prop="tweetsQuoteCount">
          <el-input v-model="form.tweetsQuoteCount" placeholder="请输入推文被引用数" />
        </el-form-item>
        <el-form-item label="推文总评论数" prop="tweetsReplyCount">
          <el-input v-model="form.tweetsReplyCount" placeholder="请输入推文总评论数" />
        </el-form-item>
        <el-form-item label="单推文最高评论数" prop="tweetsMostReplyCount">
          <el-input v-model="form.tweetsMostReplyCount" placeholder="请输入单推文最高评论数" />
        </el-form-item>
        <el-form-item label="推文中包含关键字的条数" prop="tweetsKeywordNumber">
          <el-input v-model="form.tweetsKeywordNumber" placeholder="请输入推文中包含关键字的条数" />
        </el-form-item>
        <el-form-item label="最新的推文发布时间(UTC)" prop="latestTweetTime">
          <el-date-picker clearable
            v-model="form.latestTweetTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择最新的推文发布时间(UTC)">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否优先抓取" prop="priorityCrawl">
          <el-input v-model="form.priorityCrawl" placeholder="请输入是否优先抓取" />
        </el-form-item>
        <el-form-item label="是否已经从他抓取其他人" prop="searchedOthers">
          <el-input v-model="form.searchedOthers" placeholder="请输入是否已经从他抓取其他人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTwuser, getTwuser, delTwuser, addTwuser, updateTwuser } from "@/api/system/twuser";

export default {
  name: "Twuser",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 推特用户基本信息表格数据
      twuserList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        username: null,
        name: null,
        createdAt: null,
        description: null,
        pinnedTweetId: null,
        profileImageUrl: null,
        Protected: null,
        followersCount: null,
        followingCount: null,
        tweetCount: null,
        listedCount: null,
        queryTweetsNumber: null,
        tweetsLikeCount: null,
        tweetsMostLikeCount: null,
        tweetsRetweetCount: null,
        tweetsMostRetweetCount: null,
        tweetsQuoteCount: null,
        tweetsReplyCount: null,
        tweetsMostReplyCount: null,
        tweetsKeywordNumber: null,
        latestTweetTime: null,
        priorityCrawl: null,
        searchedOthers: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        username: [
          { required: true, message: "用户名(唯一但可能会改),如:@TwitterDev不能为空", trigger: "blur" }
        ],
        priorityCrawl: [
          { required: true, message: "是否优先抓取不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询推特用户基本信息列表 */
    getList() {
      this.loading = true;
      listTwuser(this.queryParams).then(response => {
        this.twuserList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        twUserId: null,
        username: null,
        name: null,
        createdAt: null,
        description: null,
        pinnedTweetId: null,
        profileImageUrl: null,
        Protected: null,
        followersCount: null,
        followingCount: null,
        tweetCount: null,
        listedCount: null,
        queryTweetsNumber: null,
        tweetsLikeCount: null,
        tweetsMostLikeCount: null,
        tweetsRetweetCount: null,
        tweetsMostRetweetCount: null,
        tweetsQuoteCount: null,
        tweetsReplyCount: null,
        tweetsMostReplyCount: null,
        tweetsKeywordNumber: null,
        latestTweetTime: null,
        priorityCrawl: null,
        searchedOthers: null,
        updateTime: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加推特用户基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTwuser(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改推特用户基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTwuser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTwuser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除推特用户基本信息编号为"' + ids + '"的数据项？').then(function() {
        return delTwuser(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/twuser/export', {
        ...this.queryParams
      }, `twuser_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
